﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
//using Oracle.DataAccess.Client;
using System.Configuration;
using System.ComponentModel.DataAnnotations;
using trangbaocao.Models;
using System.Collections.ObjectModel;
using System.Web.Mvc;
using System.Data.OracleClient;
namespace trangbaocao.Models
{
    public class GeneratorModel
    {
        public int id { get; set; }
        public int main_stations_id { get; set; }
        public SelectList trungtam_id { get; set; }       
        public int stations_id { get; set; }
        public SelectList tram_id { get; set; }
        public int device_stations_id { get; set; }
        public int status { get; set; }
        public string ngay { get; set; }
        //Device_StationsModel Device_StationsModel = new Device_StationsModel();

        public List<GeneratorModel> getGenerator()
        {
            List<GeneratorModel> Generator = new List<GeneratorModel>();
            OracleDataReader odr = General.Lib_GetDataReader("SELECT * FROM Generator_test a,device_stations b,stations c,main_stations d where a.device_stations_id=b.id and a.stations_id=c.id and a.main_stations_id=d.id ");
            while (odr.Read())
            {
                Generator.Add(new GeneratorModel { id = Convert.ToInt32(odr["id"].ToString()), status = Convert.ToInt32(odr["status"].ToString()), device_stations_id = Convert.ToInt32(odr["device_stations_id"].ToString()), stations_id = Convert.ToInt32(odr["stations_id"].ToString()), main_stations_id = Convert.ToInt32(odr["main_stations_id"].ToString()), ngay = odr.IsDBNull(0) ? null : odr.GetDateTime(0).ToString("dd/MM/yyyy") });
            }
            return Generator;
        }
        public void updateGenerator(GeneratorModel Generator)
        {
            string sql = "UPDATE Generator SET stations_id='" + Generator.stations_id + "', main_stations_id=" + Generator.main_stations_id + ",status=0,ngay=to_date('" + Generator.ngay + "','dd/mm/yyyy')  where id=" + Generator.id;
            General.Lib_ExecuteNonQuery(sql);
        }
    }
    public class GeneratorAssociateModel
    {
        public int id { get; set; }
        public string trung_tam { get; set; }
        public string tram { get; set; }
        public int device_stations_id { get; set; }
        public int status { get; set; }
        public string ngay { get; set; }

        public List<GeneratorAssociateModel> getGeneratorIndex()
        {
            List<GeneratorAssociateModel> GeneratorAssociateModel = new List<GeneratorAssociateModel>();
            OracleDataReader odr = General.Lib_GetDataReader("SELECT a.ngay,a.id,c.name tram,d.name trung_tam,a.device_stations_id,a.status FROM Generator_test a,device_stations b,stations c,main_stations d where a.device_stations_id=b.id and a.stations_id=c.id and a.main_stations_id=d.id ");
            while (odr.Read())
            {
                GeneratorAssociateModel.Add(new GeneratorAssociateModel { id = Convert.ToInt32(odr["id"].ToString()), status = Convert.ToInt32(odr["status"].ToString()), device_stations_id = Convert.ToInt32(odr["device_stations_id"].ToString()), tram = odr["tram"].ToString(), trung_tam = odr["trung_tam"].ToString(), ngay = odr.IsDBNull(0) ? null : odr.GetDateTime(0).ToString("dd/MM/yyyy") });
            }
            return GeneratorAssociateModel;
        }     
    }
}